#include<iostream>
using namespace std;
int main()
{
	int n,m,i,s=0;
	cin>>n>>m;
	for(i=2;i<=n;i++)
		s=(s+m)%i;
	cout<<s+1;
}